var exec = require("child_process").exec;


/*function start(){
	console.log("----Request handler 'start' was called.\n");

	function sleep(milliSeconds){
		var startTime = new Date().getTime();
		while(new Date().getTime() < startTime + milliSeconds);
	}
	sleep(5000);  //模拟阻塞
	
	return 'Hello Start';
}*/

/*function start(){
	console.log("----Request handler 'start' was called.\n");
	var content = 'empty';
	exec("dir /S /b F:\ | find /i 'index.js'", function(error,stdout,stderr){
		content = stdout;
	});
	return content;
}*/

// function start(response){
// 	console.log("----Request handler 'start' was called.\n");
// // dir /S /b F:\ | find /i "index.js"
// 	exec("ls -lah", function (error, stdout, stderr) {
// 		response.write(200, {"Content-Type": "text/plain"});
// 	    response.write(stdout);
// 	    response.end();
// 	});
// }

function start(response) {
  console.log("Request handler 'start' was called.");

  exec('dir /S /b F:\ | find /i "a.js"', 
  	{ timeout: 10000, maxBuffer: 20000*1024 },
  	function (error, stdout, stderr) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write(stdout);
    response.end();
  });
}


function upload(response){
	console.log("----Request handler 'upload' was called.\n");
	response.writeHead(200,{"Content-Type":"text/plain"});
	response.write("Hello Upload");
	response.end();
}



exports.start = start;
exports.upload = upload;